package com.util;


import android.content.Context;
import android.content.res.Resources;
import android.util.TypedValue;
import android.widget.GridView;
import com.constantes.AppConstant;


public class InitGrid {

    public static int initilizeGridLayout(GridView gridView) {

        Context context = gridView.getContext();

        Resources r = context.getResources();
        float padding = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, AppConstant.GRID_PADDING, r.getDisplayMetrics());

        Utils utils = new Utils(context);
        int columnWidth = (int) ((utils.getScreenWidth() - ((AppConstant.NUM_OF_COLUMNS + 1) * padding)) / AppConstant.NUM_OF_COLUMNS);

        gridView.setNumColumns(AppConstant.NUM_OF_COLUMNS);
        gridView.setColumnWidth(columnWidth);
        gridView.setStretchMode(GridView.NO_STRETCH);
        gridView.setPadding((int) padding, (int) padding, (int) padding, (int) padding);
        gridView.setHorizontalSpacing((int) padding);
        gridView.setVerticalSpacing((int) padding);

        return columnWidth;

    }

}
